// @algorithm @lc id=413 lang=cpp 
// @title arithmetic-slices


// #define print(...)
// @test([1,2,3,4])=3
// @test([1])=0
class Solution {
public:
    int numberOfArithmeticSlices(vector<int>& nums) {
        const int n = (int)nums.size();
        if(n < 3) return 0;
        int ans = 0, d = nums[1]-nums[0], cnt = 0;
        for(int i=2; i<n; i++){
            if(d == nums[i]-nums[i-1])
                cnt ++;
            else{
                d = nums[i] - nums[i-1];
                cnt = 0;
            }
            ans += cnt;
        }
        return ans;
    }
};